<?php

class tour_model extends FlexiGrid_Model {

    function __construct()
    {
        parent::__construct();
        
    }
    function get($ID){
        $where=array("ID"=>$ID,"Delete"=>Null,"Status"=>"Public");
        $query=$this->db->get_where('tbl_tour', $where); 
        return $query->result();
    }
    function getRand(){
        $where=array("Delete"=>Null,"Status"=>"Public");
        $query=$this->db
                ->order_by('ID', 'RANDOM')
                ->get_where('tbl_tour', $where,1); 
        return $query->result();
    }
    function getByAlias($alias){
        $where=array("Alias"=>$alias,"Delete"=>Null,"Status"=>"Public");
        $query=$this->db->get_where('tbl_tour', $where); 
        return $query->result();
    }
    function insertReg($params){
        $this->db->set('Insert', 'NOW()', FALSE);
        $this->db->insert('tbl_reg', $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function insertOrderTour($params){
        $this->db->set('Insert', 'NOW()', FALSE);
        $this->db->insert('tbl_order_tour', $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function gets(){
        $where=array("Delete"=>NULL,"Status"=>"Public");
        $query=$this->db->get_where('tbl_tour', $where); 
        return $query->result();
    }
    function getType(){
        $where=array("Delete"=>NULL);
        $query=$this->db
                ->select("Type")
                ->where($where)
                ->group_by("Type")
                ->get('tbl_tour'); 
        return $query->result();
    }
    function getByType($type){
        $where=array("Delete"=>NULL,"Type"=>$type,"Status"=>"Public");
        $query=$this->db
                ->where($where)
                ->get('tbl_tour'); 
        return $query->result();
    }
}
?>
